VBArray VB Array Form1 ListBox IntDemo &Integer Array LngIntDemo &Long Integer Array OtherDemo &Some Type Array OkCancel OkCancel &Quit Status Status sTempFile hWndListBox nInitApp @ Form_Load nResult GetTempFileName9 Status Caption OkCancel_Click Index IntDemo Value) DoIntDemo VBARRAYU LngIntDemoF DoLngIntDemo OtherDemo DoOtherDemo Form_Unloadh Cancel tTempFile OFSTRUCT OpenFile OF_EXIST nRemoveTemp OF_DELETE nBeforex nAfter nBytesM hFileOut hFileIn nIObytesB nFclose lMes8 OF_CREATEW OF_WRITE lwritey lclose OF_READe lread SendMessage LB_RESETCONTENT ListBox FALSE1 lBefore lAfter tBefore SomeType tAfter nInteger sString lLong Before After Form_Paint GetFocus LB_SETTABSTOPS; fSize llseekD ptint OtherDemo_Click IntDemo_Click ListBox_Click FileSize LngIntDemo_Click trailling lFileSize OkCancel VBARRAY *FAST* file I/O of arrays Address questions/comments/improvements tom Costas Kitsos, CIS ID: 73667,1755 Enjoy! holds a Windows supplied temp filename for the demo listbox's hWnd so we can set tabs Flag for Application Initialization Form_Load Buffero Ask Windows for a temp file. Temp File: " OkCancel_Click Do the Integer Array demo Integer Demo Failed" Do the Long Integer Array demo Long Integer Demo Failed Do the SomeType Array demo Some Type Demo Failed" Quit pressedp Form_Unload Used by OpenFilei If our temp file exists, delete it. DoIntDemo Declare variables Used by OpenFile function holds the Integers before I/O holds the Integers after I/OO Integerst Use the Random number generator to fill nBefore() with 50 integers ** I/O Starts here Create our temp file and open it for writingo If we have a file handle proceed calculate the number of bytes to be written (NumberOfElements * Size) Since we want to write the entire array the formula would be: nBytes = UBound(Array) * Len(Array(element)). If we only neededS twenty elements then nBytes = 20 * Len(Array(element)). Since we're) dealing with fixed length arrays, element can be any legitimate array element.i Write nBefore() to disk using API's lwrite function. We only need to pass the first array element. The nBytes parameter tells Windows how many bytes to write, or as far as we're concerned how many array elements. Get the file size with llseek. By specifying 0 for lOffset and and 2 for iOrigin we're saying seek position 0 from the end ofh the file. In other words, give us the FileSize.r close the output file. Now let's see if it worked. Open the file for reading. We'll use the nAfter() array this time, nBytes is the same. close the input file. Let's prove that it worked. First, clear the list box. Add a title. Before After" Add the nBefore() and nAfter() contents to the listbox. Temp File: " bytes success failure DoLngIntDemo Please see the DoIntDemo function for comments Before After" Temp File: " bytes DoOtherDemo Please see the DoIntDemo function for comments abcde" Before After" Temp File: " bytes Form_Paint get the listbox's hWnd Set 1 tab stop at position 105n set the flag to FALSE so we don't repeat this